// pages/couponscheck/couponscheck.js
//获取应用实例
const app = getApp();
var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showMask: false,
    showMask2: false,
    couponsCheckDataBean: null,
    couponsCode: "",
    couponsType: "4"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var data = JSON.parse(options.bean);
    that.setData({
      couponsCheckDataBean: data,
      couponsCode: options.couponscode,
      couponsType: options.couponstype
    });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  setModalStatus: function (e) {
    var that = this;
    // this.setData({
    //   showMask: !that.data.showMask
    // })
    wx.showModal({
      title: '提示',
      content: '是否核销',
      success: function (res) {
        if (res.confirm) {
          that.sure();
        } else if (res.cancel) {

        }
      }
    })
  },
  setModalStatus2: function (e) {
    var that = this;
    this.setData({
      showMask2: !that.data.showMask2
    })
  },
  // 阻止冒泡
  clickContent: function () {
  },
  sure: function (e) {
    var that = this;
    // this.setData({
    //   showMask: !that.data.showMask
    // });
    var params = {
      code: that.data.couponsCode,
      type: that.data.couponsType
    }
    util.showLoading("审核中...");
    api.POST({
      url: app.globalData.couponscheckcheck_url,
      params: params,
      success: function (res) {
        wx.hideLoading();
        if (util.isEmpty(res.data.code)) {
          // that.setData({
          //   showMask2: !that.data.showMask2
          // });

          wx.showModal({
            title: '提示',
            content: '核销成功',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({
                  delta: 1
                });
              }
            }
          })

        } else {
          util.showError(res.data.message);
        }

      },
      fail: function (res) {
        wx.hideLoading();
        util.showError("请检查网络");
      }
    });
  },


  nextscan: function () {
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];   //当前页面
    var prevPage = pages[pages.length - 2];  //上一个页面

    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      scan: true
    });
    wx.navigateBack({
      delta: 1
    });
  }
  ,
  gogoods: function () {
    // wx.redirectTo({
    //   url: '../center/orderRecored/orderRecored'
    // });
    var that = this;
    this.setData({
      showMask2: !that.data.showMask2
    });
  }
})